package com.kakarote.hbase.service;

import com.kakarote.hbase.config.HBaseTemplate;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Service
public class UserService {

    private final HBaseTemplate hBaseTemplate;

    public UserService(HBaseTemplate hBaseTemplate) {
        this.hBaseTemplate = hBaseTemplate;
    }

    public void createUserTable() throws IOException {
        hBaseTemplate.createTable("users", "info");
    }

    public void addUser(String id, String name, String email) throws IOException {
        Map<String, String> data = new HashMap<>();
        data.put("name", name);
        data.put("email", email);
        hBaseTemplate.putData("users", id, "info", data);
    }

    public User getUser(String id) throws IOException {
        Map<String, String> data = hBaseTemplate.getData("users", id, "info");
        return new User(id, data.get("name"), data.get("email"));
    }
}
